﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace Tunnel_Cross_Section.相关类
{
   public  class Projects
    {
        [DllImport("kernel32.dll")]
        public static extern int GetPrivateProfileString(string section, string key,
              string def, StringBuilder retval, int size, string filepath);

        [DllImport("kernel32")]
        private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);

       public string line_name;
       public string section_name;
       public int id;
       public Projects(string name1,string name2)
       {
           if (name1 == string.Empty || name2==string.Empty)
           {
               throw new Exception("项目的名称不能为空!");
               
           }
           line_name = name1;
           section_name = name2;
       }
       public Projects()
       {
 
       }
       private string path = System.Windows.Forms.Application.StartupPath + @"\config.ini";
       public void SetAngleStep(double start, double end, double step)
       {
           WritePrivateProfileString(this.id.ToString(), "startA", start.ToString(), path);
           WritePrivateProfileString(this.id.ToString(), "endA", end.ToString(), path);
           WritePrivateProfileString(this.id.ToString(), "stepA", step.ToString(), path);
       }
       public void GetAngleStep(out double startA, out double endA, out double stepA)
       {
         
           StringBuilder startAstr = new StringBuilder(40);
           StringBuilder endAstr = new StringBuilder(40);
           StringBuilder stepAstr = new StringBuilder(40);
           string def = "";
           GetPrivateProfileString(this.id.ToString(), "startA", def, startAstr, 40, path);
           GetPrivateProfileString(this.id.ToString(), "endA", def, endAstr, 40, path);
           GetPrivateProfileString(this.id.ToString(), "stepA", def, stepAstr, 40, path);
           try
           {
               startA = Convert.ToDouble(startAstr.ToString());
               endA = Convert.ToDouble(endAstr.ToString());
               stepA = Convert.ToDouble(stepAstr.ToString());
           }
           catch
           {
               startA = 41.5;
               endA = 317.5;
               stepA = 5;
           }
           
       }
       public bool IsSepecial()
       {
           double a, b, c;
           GetAngleStep(out a, out b, out c);
           if (b == 317.5 && c == 5)
           {
               return false;
           }
           else
           {
               return true;
           }
       }
    }
}
